package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IUserRoleDAO;
import com.ecommerce.dal.entity.UserCommunication;
import com.ecommerce.dal.entity.UserRole;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("userRoleDAO")
public class UserRoleDAO extends CustomHibernateDAOSupport implements
		IUserRoleDAO {

	@Override
	public void save(UserRole userRole) {
		getHibernateTemplate().save(userRole);

	}

	@Override
	public void update(UserRole userRole) {
		getHibernateTemplate().update(userRole);
	}

	@Override
	public void delete(UserRole userRole) {
		getHibernateTemplate().delete(userRole);

	}

	@Override
	public List<UserRole> findByUserRoleId(long userRoleId) {
		List list = getHibernateTemplate()
				.find("select userRole from UserRole userRole where userRole.userRoleId=?",
						userRoleId);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

	@Override
	public List<UserRole> findByAuthority(String authority) {
		List list = getHibernateTemplate()
				.find("select userRole from UserRole userRole where userRole.authority=?",
						authority);
		return ((list != null && list.size()>0) ?  list : null) ;
	}
}
